# DataLink Actor持久化功能 - Docker镜像
FROM openjdk:8-jre-alpine

# 维护者信息
LABEL maintainer="DataLink Team <team@datalink.com>"
LABEL version="1.0.0"
LABEL description="DataLink Actor Persistence System"

# 设置工作目录
WORKDIR /app

# 创建应用用户
RUN addgroup -g 1000 datalink && \
    adduser -D -s /bin/sh -u 1000 -G datalink datalink

# 安装必要的工具
RUN apk add --no-cache \
    curl \
    bash \
    tzdata \
    && rm -rf /var/cache/apk/*

# 设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 创建必要的目录
RUN mkdir -p /app/config \
             /app/data \
             /app/logs \
             /app/lib \
             /app/bin && \
    chown -R datalink:datalink /app

# 复制应用文件
COPY --chown=datalink:datalink target/datalink-*.jar /app/datalink.jar
COPY --chown=datalink:datalink docker/config/ /app/config/
COPY --chown=datalink:datalink docker/scripts/ /app/bin/

# 设置执行权限
RUN chmod +x /app/bin/*.sh

# 环境变量配置
ENV JAVA_OPTS="-Xms2g -Xmx4g -XX:+UseG1GC -XX:MaxGCPauseMillis=200"
ENV DATALINK_HOME="/app"
ENV DATALINK_CONFIG_PATH="/app/config"
ENV DATALINK_DATA_PATH="/app/data"
ENV DATALINK_LOG_PATH="/app/logs"

# 持久化配置 - 已迁移到H2数据库
ENV PERSISTENCE_ENABLED="false"
ENV PERSISTENCE_STORAGE_PATH="/app/data/h2"
ENV PERSISTENCE_STORAGE_TYPE="h2"
ENV PERSISTENCE_SNAPSHOT_INTERVAL="1000"
ENV PERSISTENCE_METRICS_ENABLED="true"

# 集群配置
ENV CLUSTER_ENABLED="false"
ENV CLUSTER_SEED_NODES=""
ENV CLUSTER_PORT="2551"

# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:8080/actuator/health || exit 1

# 暴露端口
EXPOSE 8080 2551 9999

# 数据卷
VOLUME ["/app/data", "/app/logs", "/app/config"]

# 切换到应用用户
USER datalink

# 启动脚本
ENTRYPOINT ["/app/bin/docker-entrypoint.sh"]
CMD ["start"]
